package com.twinkle.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.twinkle.dao.ClassifierParamMapper;
import com.twinkle.model.ClassifierParam;
import com.twinkle.model.ClassifierParamUI;
import com.twinkle.service.ClassifierParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;

/**
 * @title: ClassifierParamServiceImpl
 * @description:
 * @author: Paul
 * @date: 2023/3/17 14:56
 */
@Service
public class ClassifierParamServiceImpl implements ClassifierParamService {

    @Autowired
    ClassifierParamMapper classifierParamMapper;

    @Override
    public String addClassifierParam(ClassifierParamUI classifierParamUI) throws ParseException {
        ClassifierParam classifierParam = new ClassifierParam();
        classifierParam.setId(classifierParamUI.getId());
        classifierParam.setAppName(classifierParamUI.getAppName());
        classifierParam.setDataSourceId(classifierParamUI.getDataSourceId());
        classifierParam.setTableName(classifierParamUI.getTableName());
        classifierParam.setFeatureCols(JSONObject.toJSONString(classifierParamUI.getFeatureCols()));
        classifierParam.setClassCols(JSONObject.toJSONString(classifierParamUI.getClassCols()));
        classifierParam.setPreProcessMethodList(JSONObject.toJSONString(classifierParamUI.getPreProcessMethodList()));
        classifierParam.setAlgoParam(JSONObject.toJSONString(classifierParamUI.getAlgoParam()));
        classifierParam.setTrainDataRatio(classifierParamUI.getTrainDataRatio());
        int insert = classifierParamMapper.insert(classifierParam);
        return "sucess";
    }
}
